const express = require('express')

const app = express()

const mw1 = (req, res, next) => {
  console.log('局部生效的中间件1')
  next()
}

const mw2 = (req, res, next) => {
  console.log('局部生效的中间件2')
  next()
}

// 多个局部注册的中间件函数，会依次执行
// app.get('/', mw1, mw2, (req, res) => { 
//   res.send('Home page.')
//   console.log('访问了/路径')
// })

app.get('/', [mw1, mw2], (req, res) => { 
  res.send('Home page.')
  console.log('访问了/路径')
})

app.get('/user', (req, res) => { 
  res.send('user page.')
  console.log('访问了/user路径')
})

app.listen(80, () => {
  console.log('express server running at http://127.0.0.1')
})